import os
import glob
import json
import sys
sys.path.append(r'.')
from PIL import Image




def images(imageTop,imageProduct,imageEnd,imageOut):
    # 创建一个新的400x400像素大小的白色背景图像
    new_image = Image.new('RGB', (1440, 5180), 'black')

    # 将四个图像粘贴到新图像的正确位置
    image_one = Image.open(imageTop).resize((1440, 848))
    new_image.paste(image_one, (0, 0))

    image_two = Image.open(imageProduct).resize((1440, 2375))
    new_image.paste(image_two, (0, 1400))

    image_three = Image.open(imageEnd).resize((1440, 707))
    new_image.paste(image_three, (0, 4473))
    # 将最终图像保存到磁盘上
    new_image.save(imageOut)

def load_param_datas_from_file(file_path):
    with open(file_path, "r", encoding='utf-8') as f:
        json_file_datas = json.loads(f.read())    # load的传入参数为字符串类型
        return json_file_datas
def run_json_file():
    print('-------------------开始合成图片-----------------------------------------')
    json_file_datas = load_param_datas_from_file('douyin_image.data.json')
    imageTop = json_file_datas['imageTop']
    imageProduct = json_file_datas['imageProduct']
    imageEnd = json_file_datas['imageEnd']
    imageOut = json_file_datas['imageOut']
    images(imageTop,imageProduct,imageEnd,imageOut)
    print('-------------------下载结果-----------------------------------------')


run_json_file();
